//
//  ZLAlertMainView.swift
//  ZLAlert
//
//  Created by 赵振磊 on 2022/11/27.
//

import UIKit

class ZLAlertMainView: UIView {
    /// 输入框
    var textField: UITextField?
    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        if (self.textField != nil) {
            let inside = self.textField!.frame.contains(point)
            if (inside) {
                return self.textField
            }
            let tapView = self.getPointTextField(point: point)
            if (tapView != nil) {
                return tapView
            }
            self.textField?.endEditing(true)
            return nil
        }
        return super.hitTest(point, with: event)
    }
    override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
        if (self.textField != nil) {
            return false
        }
        return super.point(inside: point, with: event)
    }
    
    func getPointTextField(point: CGPoint) -> UITextField? {
        for view in self.subviews {
            if (!view.isKind(of: UITextField.self)) {
                continue
            }
            let textField = view as! UITextField
            let inside = textField.frame.contains(point)
            if (!inside) {
                continue
            }
            return textField
        }
        return nil
    }
}
